package com.xh.bussiness.practice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xh.bussiness.practice.bean.request.PracticeDetailRequest;
import com.xh.bussiness.practice.model.PracticeDetail;
import com.xh.bussiness.practice.dao.PracticeDetailMapper;
import com.xh.bussiness.practice.service.IPracticeDetailService;
import com.xh.core.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import com.xh.core.bean.XhPage;
import com.xh.core.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 作业详情表 服务实现类
 * </p>
 *
 * @author Pitt
 * @since 2021-01-26
 */
@Service
public class PracticeDetailServiceImpl extends BaseServiceImpl<PracticeDetailMapper, PracticeDetail> implements IPracticeDetailService {
    @Override
    public XhPage queryPracticeDetailPage(XhPage page, PracticeDetailRequest bean) {
        QueryWrapper qw=new QueryWrapper<PracticeDetail>();
        //拼装条件
        qw=prepareParams(bean, qw);

        return (XhPage) this.dao.selectPage(page,qw);
    }

    @Override
    public List queryPracticeDetail(PracticeDetailRequest bean) {
        QueryWrapper qw=new QueryWrapper<PracticeDetail>();
        //拼装条件
        qw=prepareParams(bean, qw);

        return this.dao.selectList(qw);
    }

    @Override
    public void deleteByPracticeId(String practiceId) {
        this.dao.deleteByPracticeId(practiceId);
    }

    /**
     * 准备条件
     * @param bean
     * @param qw
     */
    private QueryWrapper prepareParams(PracticeDetailRequest bean, QueryWrapper qw) {
        if(bean.getIds()!=null&&bean.getIds().length>0){
            qw.in("id",bean.getIds());
        }
        if (!StringUtils.isEmpty(bean.getPracticeId())) {
            qw.eq("practice_id", bean.getPracticeId());
        }
        return qw;
    }

}
